-- The MIT License (MIT)
-- Copyright (c) 2016 Yanghe Sun

--luacheck: no global
--luacheck: no unused args

local luaunit  = require("luaunit")
local compiler = require("compiler")();

Test_compiler = {}

function Test_compiler:testInvaildExt()
    luaunit.assertNil(compiler:_GetRawCommand("123.bmp"));
end

function Test_compiler:testDefaultCommand()
    luaunit.assertEquals(compiler:_GetRawCommand("123.cpp"), "g++ 123.cpp -O2 -o 123.out");
    luaunit.assertEquals(compiler:_GetRawCommand("123.c"), "gcc 123.c -O2 -o 123.out");
    luaunit.assertEquals(compiler:_GetRawCommand("123.pas"), "fpc 123.pas");
end

function Test_compiler:testCustomCommand()
    local c = require("compiler")();
    c:LoadRules("./testcases/lang.lua");
    luaunit.assertEquals(c:_GetRawCommand("123.cpp"), "g++ 123.cpp -O3 -o 123.out");
    luaunit.assertEquals(c:_GetRawCommand("123.c"), "gcc 123.c -O2 -o 123.out");
    luaunit.assertEquals(c:_GetRawCommand("123.pas"), "fpc 123.pas");
end

function Test_compiler:testCompile()
    local ret = compiler:Compile("./testcases/normal.c");
    luaunit.assertTrue(ret.success);
    ret = compiler:Compile("./testcases/normal.pas");
    luaunit.assertTrue(ret.success);
end

function Test_compiler:testSelect()
    local srcs = { "apb.c", "apb.pas", "111.cpp" };
    local ret = compiler:Select("apb", srcs);
    luaunit.assertEquals(ret, "apb.c");
end
